<?php
function my_theme_setup() {
    add_theme_support('title-tag');
    add_theme_support('post-thumbnails');
    register_sidebar(array(
        'name' => __('Sidebar', 'my-simple-theme'),
        'id' => 'sidebar-1',
        'description' => __('Widgets in this area will be shown on all posts and pages.', 'my-simple-theme'),
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h2 class="widget-title">',
        'after_title' => '</h2>',
    ));

    // Register navigation menu
    register_nav_menus(array(
        'primary' => __('Primary Menu', 'my-simple-theme')
    ));
}
add_action('after_setup_theme', 'my_theme_setup');

function enqueue_my_styles() {
    wp_enqueue_style('my-style', get_stylesheet_uri(), array(), filemtime(get_template_directory() . '/style.css'));
}
add_action('wp_enqueue_scripts', 'enqueue_my_styles');

// 添加自定义评论显示函数
function custom_comment_display($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment;
    ?>
    <div <?php comment_class('comment-item'); ?> id="comment-<?php comment_ID(); ?>">
        <div class="comment-avatar">
            <?php echo get_avatar($comment, $args['avatar_size']); ?>
        </div>
        <div class="comment-body">
            <div class="comment-meta">
                <span class="comment-author"><?php comment_author_link(); ?></span>
                <span class="comment-date"><?php echo get_comment_date() . ' ' . get_comment_time(); ?></span>
            </div>
            <?php if ($comment->comment_approved == '0') : ?>
                <p class="comment-awaiting-moderation">您的评论正在等待审核。</p>
            <?php endif; ?>
            <div class="comment-content">
                <?php comment_text(); ?>
            </div>
            <div class="comment-reply">
                <?php comment_reply_link(
                    array_merge(
                        $args,
                        array(
                            'depth' => $depth,
                            'max_depth' => $args['max_depth'],
                            'reply_text' => '回复'
                        )
                    )
                ); ?>
            </div>
        </div>
    </div>
    <?php
}

// 确保评论查询正常工作
add_action('pre_get_comments', function($query) {
  if (is_single()) {
      $query->query_vars['post_id'] = get_the_ID();
      $query->query_vars['status'] = 'approve';
  }
});

// 确保评论功能启用
add_filter('comments_open', function($open, $post_id) {
    return true;
}, 10, 2);

?>
